//圆形封装
function ItcastArc(option) {
    this._init(option);
}
ItcastArc.prototype = {
    _init: function (option) {
        this.x = option.x == 0 ? 0 : option.x;
        this.y = option.y == 0 ? 0 : option.y;
        //画布旋转角度
        this.angle = option.angle == 0 ? 0 : option.angle || 0;
        this.fillStyle = option.fillStyle || 'red';
        this.strokeStyle = option.strokeStyle || 'black';
        this.strokeWidth = option.strokeWidth || 4;
        this.scaleX = option.scaleX || 1;
        this.scaleY = option.scaleY || 1;
        this.opacity = option.opacity || 1;
        this.counterclockwise = option.counterclockwise == true ? true : option.counterclockwise || false;
        this.startAngle = option.startAngle == 0 ? 0 : option.startAngle || 0;
        this.endAngle = option.endAngle == 0 ? 0 : option.endAngle || 0;
        this.startAngle = this.startAngle * Math.PI / 180;
        this.endAngle = this.endAngle * Math.PI / 180;
        this.r = option.r || 100;
    },
    render: function (ctx) {
        ctx.save();
        ctx.beginPath();
        ctx.translate(this.x, this.y);
        ctx.rotate(this.angle * Math.PI / 180);
        ctx.scale(this.scaleX, this.scaleY);

        ctx.strokeStyle = this.strokeStyle;
        ctx.fillStyle = this.fillStyle;
        ctx.grobalAlpha = this.opacity;

        //一整个圆形填充不需要以下代码，否则会多出一条线；其他角度要以下代码，否则无法填充扇形
        // ctx.moveTo(0, 0);
        ctx.arc(
            0,
            0,
            this.r,
            this.startAngle,
            this.endAngle,
            this.counterclockwise
        );
        ctx.fill();
        ctx.stroke();
        ctx.closePath();
        ctx.restore();

    }
}